package com.example.testproj.C407;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.testproj.R;

public class ScaleGestureDetectorActivity extends AppCompatActivity {
    private static final String TAG = "ScaleGestureDetectorAct";
    private ScaleGestureDetector mScaleGestureDetector;
    private ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scale_gesture_detector);
        imageView= (ImageView) findViewById(R.id.imageview);

        ScaleGestureDetector.SimpleOnScaleGestureListener simpleOnScaleGestureListener=new ScaleGestureDetector.SimpleOnScaleGestureListener(){
            @Override
            public boolean onScale(ScaleGestureDetector detector) {
                Log.d(TAG, "onScale: "+ detector.getScaleFactor());
                ViewGroup.LayoutParams layoutParams=imageView.getLayoutParams();
                layoutParams.height= (int) (imageView.getLayoutParams().height*detector.getScaleFactor());
                layoutParams.width= (int) (imageView.getLayoutParams().width*detector.getScaleFactor());
//                imageView.setLayoutParams(layoutParams);
                imageView.requestLayout();
                return super.onScale(detector);
            }
        };
        mScaleGestureDetector = new ScaleGestureDetector(this,simpleOnScaleGestureListener);

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        mScaleGestureDetector.onTouchEvent(event);
        return super.onTouchEvent(event);
    }
}
